define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    require('../../../xsyBase');

    var map = {
        y: 'follow-join.action',
        n: 'unfollow.action'
    };

    $.widget('rk.xsyFavouriteButton', $.rk.xsyBase, {
        _params:{},
        _create: function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;

            me._super();
        },

        _init:function() {
            var me = this;
            var elem = me.element;
            var opt = me.options;
          
            elem.on('click', function (evt) {
                evt.preventDefault();
                var $lnk = $(this),
                    isAdd = $lnk.hasClass('xsy_su_header_follow') ? 'y' : 'n';

                $.post('/json/sns_group/' + map[isAdd], {
                    groupId: me._getGroupId()
                }, null, 'json').done(function (json) {
                    if (json.status == 0) {
                        if(isAdd == 'y'){
                            elem.removeClass('xsy_su_header_follow').addClass('xsy_su_header_hasfollow');
                            elem.html('<i></i>已关注');
                            elem.attr('title', "取消关注");
                        }else{
                            elem.removeClass("xsy_su_header_hasfollow").addClass('xsy_su_header_follow');
                            elem.html('<i></i>加关注');
                            elem.attr('title', '加关注');
                        }
                    }
                }).fail(function (def, code, message) {
                    def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
                });
            });
        }
    });
});